#include "OutlineSection.h"

OutlineSection::OutlineSection(){
	title = "";
	description = "";
	comments = "";
    needsUpdate = false;
}

OutlineSection::OutlineSection(QString newTitle, QString newDescription, bool newOptional,
                               QString newText, bool newDefTextRequired, bool newHasDates)
{
    this->title=newTitle;
    this->description=newDescription;
    this->optional=newOptional;
    this->text=newText;
    this->defTextRequired=newDefTextRequired;
    this->hasDates=newHasDates;
    comments="";
    needsUpdate=false;
}

QString OutlineSection::getTitle() const{
    return this->title;
}

QString OutlineSection::getDescription() const{
    return this->description;
}

QString OutlineSection::getComments() const{
    return this->comments;
}

QString OutlineSection::getText() const{
    return this->text;
}
QString OutlineSection::getText()
{
    return this->text;
}

void OutlineSection::setTitle(QString newTitle){
    this->title = newTitle;
}

void OutlineSection::setDescription(QString newDescription){
    this->description = newDescription;
}

void OutlineSection::setComments(QString newComments) {
    this->comments = newComments;
    this->needsUpdate = true;
}

bool OutlineSection::isUpdated() const{
    return !this->needsUpdate;
}

bool OutlineSection::isOptional() const{
    return this->optional;
}

bool OutlineSection::doesHaveDates() const{
    return this->hasDates;
}

bool OutlineSection::isDefTextRequired() const{
    return this->defTextRequired;
}

void OutlineSection::setText(QString newText)
{
    this->text = newText;
//    this->needsUpdate = false;
}

bool OutlineSection::clearComments(){
	if(needsUpdate){
		return false;
	}
	else{
		this->comments = "";
		return true;
	}
}

QDataStream &operator<<(QDataStream &out, const OutlineSection &data)
{
    out << data.getTitle() << data.getDescription() << data.isOptional() << data.getComments() << data.getText() << data.isDefTextRequired() << data.doesHaveDates();
    return out;
}

QDataStream &operator>>(QDataStream &in, OutlineSection &data)
{
    QString title;
    QString description;
    QString newText;
    QString comments;
    bool optional;
    bool defTextRequired;
    bool hasDates;
    bool needsUpdate;
    in >> title >> description >> optional >> comments >> newText >> defTextRequired >> hasDates;
    data = OutlineSection(title, description, optional, newText, defTextRequired, hasDates);
//    if(comments != ""){
//        data.setComments(comments);
//    }
    return in;
}
